#ifndef __SPINLOCK_H__
#define __SPINLOCK_H__
/*
 * =====================================================================================
 * Copyright (C) 2023 Ingenic Semiconductor Co.,Ltd
 * All Rights Reserved
 *
 * Filename     : spinlock.h
 * Author       : Keven <keven.ywhan@ingenic.com>
 * Created      : 2024/06/19 11:23
 * Description  :
 *
 * =====================================================================================
 */

#include "irqflags.h"
#include "arch_spinlock.h"

typedef struct spinlock {
	const char *name;
	short count;
	short is_irq;
	arch_spinlock_t arch_lock;
} spinlock_t;

void spin_lock_init(spinlock_t *lock);
void spin_lock(spinlock_t *lock);
void spin_unlock(spinlock_t *lock);
void spin_lock_irq(spinlock_t *lock);
void spin_unlock_irq(spinlock_t *lock);

#define spin_lock_irqsave(lock, flags)  \
	do {                            \
		local_irq_save(flags);  \
		spin_lock(lock);        \
	} while (0)

#define spin_unlock_irqrestore(lock, flags) \
	do {                                \
		spin_unlock(lock);          \
		local_irq_restore(flags);   \
	} while (0)

#endif /* __SPINLOCK_H__*/
